package com.hsgene.order.listener;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.Message;
import com.hsgene.common.util.result.ApiResult;
import com.hsgene.common.util.result.NullObject;
import com.hsgene.order.service.ConsoleOrderService;
import com.hsgene.util.mq.rocket.annotation.RocketMQListener;
import com.hsgene.util.mq.rocket.consumer.AbstractRocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

/**
 * 商城订单自动收货消息监听
 *
 * @author wangbing
 * @version 1.0
 * @date 2019/1/30 14:59
 * Copyright: Copyright (c) 2019
 */
@RocketMQListener(topic = "genetic_testing_order", tag = "genetic_testing_order_auto_receipt")
public class OrderAutoReceiptListener extends AbstractRocketMQListener {

    private final static Logger LOGGER = LoggerFactory.getLogger(OrderAutoReceiptListener.class);

    @Resource
    private ConsoleOrderService consoleOrderService;

    @Override
    public Action messageHandler(Message message) {
        LOGGER.info("收到商城订单自动收货消息，message = {}", message);
        ApiResult<NullObject> result = consoleOrderService.handleAutoReceiptMsg(new String(message.getBody()));
        if (!result.isSucc()) {
            LOGGER.error("商城订单自动收货消息处理失败：reason = {}", result.getDesc());
        }
        return result.isSucc() ? Action.CommitMessage : Action.ReconsumeLater;
    }
}
